# _*_coding : utf-8_*_
# @Author : lzy
# @Date : 2024-4-13 9:23
# @Desc : 此文件的作用

from tkinter import *
import json


def save_window_geometry(window, filename="main_page_config.json"):
    width, height = window.winfo_width(), window.winfo_height()
    geometry = {"width": width, "height": height}
    with open(filename, "w") as f:
        json.dump(geometry, f)

def load_window_geometry(window, default_size=(240, 240), filename="main_page_config.json"):
    if os.path.exists(filename):
        with open(filename, "r") as f:
            settings = json.load(f)
            width = settings.get("width", default_size[0])
            height = settings.get("height", default_size[1])
    else:
        width, height = default_size
    window.geometry(f"{width}x{height}")

if __name__ == '__main__':
    root = Tk()
    root.title("K哥组织小工具")
    # 加载之前保存的窗口大小，或使用默认大小
    load_window_geometry(root)

    # 在窗口关闭时保存当前大小
    root.protocol("WM_DELETE_WINDOW", lambda: (save_window_geometry(root), root.destroy()))
    root.mainloop()